#!/bin/sh

uci set luci.main.lang=zh_cn
uci commit luci

uci set system.@system[0].timezone=CST-8
uci set system.@system[0].zonename=Asia/Shanghai
uci set system.@watchcat[0].period='30m'
uci set system.@watchcat[0].pinghosts='223.5.5.5'
uci commit system


sed -i 's/root::0:0:99999:7:::/root:$1$GFK0.z0N$nACoq69YxKMOLjpjXMXVH0:19835:0:99999:7:::/g' /etc/shadow
sed -i 's/root:::0:99999:7:::/root:$1$GFK0.z0N$nACoq69YxKMOLjpjXMXVH0:19835:0:99999:7:::/g' /etc/shadow

uci add rtty rtty 
uci set rtty.@rtty[0].host='111.21.154.20'
uci set rtty.@rtty[0].port='5912'
uci set rtty.@rtty[0].token='Lr@548784*18809200101'
uci commit


if [ -f /etc/init.d/firewall4 ]; then
    # firewall4 处理方式
    # 推荐用uci添加规则，或写入/etc/nftables.d/自定义文件
    # 例如添加一个accept规则
    uci add firewall rule
    uci set firewall.@rule[-1].name='Allow-TincTun'
    uci set firewall.@rule[-1].src='*'
    uci set firewall.@rule[-1].proto='all'
    uci set firewall.@rule[-1].target='ACCEPT'
    uci set firewall.@rule[-1].in='tinctun'
    uci commit firewall
else
    # firewall3 处理方式
    # 推荐写入/etc/firewall.user自定义规则
    echo -e "iptables -A input_rule -i tinctun -j ACCEPT" >> /etc/firewall.user
    echo -e "iptables -A forwarding_rule -i tinctun -j ACCEPT" >> /etc/firewall.user
    echo -e "iptables -A forwarding_rule -o tinctun -j ACCEPT" >> /etc/firewall.user
    echo -e "iptables -A output_rule -o tinctun -j ACCEPT" >> /etc/firewall.user
    echo -e "iptables -I FORWARD -s 192.168.254.0/24 -j ACCEPT" >> /etc/firewall.user

fi

#the wireless config
sed -i '/option disabled/d' /etc/config/wireless
sed -i '/set wireless.radio${devidx}.disabled/d' /lib/wifi/mac80211.sh
:<<wireless-config
sed -i "s/\(ssid=\)OpenWrt/\1qdcloud_$(cat /sys/class/ieee80211/${dev}/macaddress|awk -F ":" '{print $4""$5""$6 }'| tr a-z A-Z)/" /lib/wifi/mac80211.sh
sed -i "s/\(encryption=\)none/\1psk-mixed/" /lib/wifi/mac80211.sh
sed -i '/set wireless.default_radio${devidx}.ssid=qdcloud/a\\t\t\tset wireless.default_radio${devidx}.key=qdcloud@2022' /lib/wifi/mac80211.sh
wireless-config



exit 0
